<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * @var \Magento\CurrencySymbol\Block\Adminhtml\System\Currencysymbol $block
 */
?>

<?php $block->getCurrencySymbolsData();?>

<form id="currency-symbols-form" action="<?php /* @escapeNotVerified */ echo $block->getFormActionUrl() ?>" method="post">
    <input name="form_key" type="hidden" value="<?php /* @escapeNotVerified */ echo $block->getFormKey() ?>" />
    <fieldset class="admin__fieldset">
        <?php foreach ($block->getCurrencySymbolsData() as $code => $data): ?>
        <div class="admin__field _required">
            <label class="admin__field-label" for="custom_currency_symbol<?php /* @escapeNotVerified */ echo $code; ?>">
                <span><?php /* @escapeNotVerified */ echo $code; ?> (<?php /* @escapeNotVerified */ echo $data['displayName']; ?>)</span>
            </label>
            <div class="admin__field-control">
                <input id="custom_currency_symbol<?php /* @escapeNotVerified */ echo $code; ?>"
                       class="required-entry admin__control-text"
                       type="text"
                       value="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($data['displaySymbol']); ?>"
                       <?php echo $data['inherited'] ? ' disabled="disabled"' : '';?>
                       name="custom_currency_symbol[<?php /* @escapeNotVerified */ echo $code; ?>]">
                <div class="admin__field admin__field-option">
                    <input id="custom_currency_symbol_inherit<?php /* @escapeNotVerified */ echo $code; ?>"
                           class="admin__control-checkbox" type="checkbox"
                           onclick="toggleUseDefault(<?php /* @escapeNotVerified */ echo '\'' . $code . '\',\'' . $block->escapeQuote($data['parentSymbol'], true) . '\''; ?>)"
                            <?php echo $data['inherited'] ? ' checked="checked"' : ''; ?>
                           value="1"
                           name="inherit_custom_currency_symbol[<?php /* @escapeNotVerified */ echo $code; ?>]">
                    <label class="admin__field-label" for="custom_currency_symbol_inherit<?php /* @escapeNotVerified */ echo $code; ?>"><span><?php /* @escapeNotVerified */ echo $block->getInheritText(); ?></span></label>
                </div>
            </div>
        </div>
        <?php endforeach; ?>
    </fieldset>
</form>
<script>
require(['jquery', "mage/mage", 'prototype'], function(jQuery){

    jQuery('#currency-symbols-form').mage('form').mage('validation');

    function toggleUseDefault(code, value)
    {
        checkbox = $('custom_currency_symbol_inherit'+code);
        input = $('custom_currency_symbol'+code);
        if (checkbox.checked) {
            input.value = value;
            input.disabled = true;
        } else {
            input.disabled = false;
        }
    }

    window.toggleUseDefault = toggleUseDefault;
});
</script>
